package com.itany.corejava.day10;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;

public class TestMap {

    public static void main(String[] args) {

        Map<String,Integer> m=new HashMap<>();
        // Map<String,Integer> m=new Hashtable<>();


        m.put("a",1);
        m.put("b",2);
        m.put("c",3);
        m.put(null,null);

        System.out.println(m);

        m.put("a",4);

        System.out.println(m);

        System.out.println("-----------------------");

        Set<String> keySet=m.keySet();

        for (String key : keySet) {
            System.out.println(key+"="+m.get(key));
        }

        System.out.println("-----------------------");

        //Map中每一对key和value是Entry类型，Entry是Map的内部类

        Set<Map.Entry<String,Integer>> entrySet=m.entrySet();

        for (Map.Entry<String, Integer> entry : entrySet) {
            System.out.println(entry.getKey()+"="+entry.getValue());
        }

    }

}
